package top.z.orm.handle.osql.name;

import top.z.orm.core.osql.NameTranslate;
import top.z.orm.handle.osql.core.HoneyConfig;

/**
 * JAVA驼峰命名与DB下划线命名互转
 * DB <==> Java, eg: order_no <==> orderNo
 */
public class UnderScoreAndCamelName implements NameTranslate {

    @Override
    public String toTableName(String entityName) {
        return NameUtil.toUnderscore(entityName);
    }

    @Override
    public String toColumnName(String fieldName) {
        return NameUtil.toCamelcase(fieldName);
    }

    @Override
    public String toEntityName(String tableName) {
        if (HoneyConfig.getHoneyConfig().isDbNamingToLowerCaseBefore()) {
            tableName = tableName.toLowerCase();
        }
        return NameUtil.firstLetterToUpperCase(NameUtil.toCamelcase(tableName));
    }

    @Override
    public String toFieldName(String columnName) {
        if (HoneyConfig.getHoneyConfig().isDbNamingToLowerCaseBefore()) {
            columnName = columnName.toLowerCase();
        }
        return NameUtil.toCamelcase(columnName);
    }
}